package com.tycmc.signelectroniccontracts.tools.store;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.tycmc.signelectroniccontracts.tools.show.LogShow;


/**
 * Created by gy on 2017/9/25.
 */

public class SqlitTool extends SQLiteOpenHelper {
    public static final String TAG = "SqlitTool";
    public static final int DB_VERSION = 1;
    public static final String DB_NAME = "zuulin";//数据库
    public static final String TABLE_PDF = "PDFURL";//数据库表名存放信息的
    private static SQLiteDatabase database;

    public static SQLiteDatabase getDatabase(Context context) {
        if (database == null) {
            database = new SqlitTool(context).getReadableDatabase();
        }
        return database;
    }

    public SqlitTool(Context context) {
        this(context, DB_NAME, DB_VERSION);
    }

    public SqlitTool(Context context, String name, int version) {
        this(context, name, null, version);
    }

    public SqlitTool(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);

    }


    /**
     * 创建数据库
     *
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_PDF + "(" +
                " id integer  primary key ," +
                " position varchar(1000)," +
                " urlpath varchar(1000)," +
                " ordernum integer)");
    }

    /**
     * 更新数据库
     *
     * @param db         数据库操作对象
     * @param oldVersion 旧版本号
     * @param newVersion 新版本号
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        LogShow.i(TAG, "oldVersion：" + oldVersion + "\nnewVersion：" + newVersion);
    }

}
